<?php 
class CategoryController extends Controller
{
	private $format = 'json';
	
	public function actionLoad()
	{
		//get type
		if(isset($_REQUEST['categoryType']))
		{
			$categoryType = $_REQUEST['categoryType'];
			if ($categoryType == 1)
			{
				$sql = 'select ArticleCategoryId , ArticleCategoryName from tbl_category where ArticleCategoryParentId = -1; ';
				$connection=Yii::app()->db;
				$command=$connection->createCommand($sql);
				$dataReader=$command->query();
				$rows=$dataReader->readAll();
				ResponseWrapHelper::_sendResponse(200,CJSON::encode($rows));
			}
			else if($categoryType == 2){
				$mainCategoryId = $_REQUEST['mainCategory'];
				$sql = 'select ArticleCategoryId , ArticleCategoryName from tbl_category where ArticleCategoryParentId =  '.$mainCategoryId .';';
				$connection=Yii::app()->db;
				$command=$connection->createCommand($sql);
				$dataReader=$command->query();
				$rows=$dataReader->readAll();
				ResponseWrapHelper::_sendResponse(200,CJSON::encode($rows));
			}
		}
	}
}